<template><div>
	<n-input type="textarea"
	         placeholder="输入题目文本"
				v-model:value="text"></n-input>
	<p>题目字符数:{{text.length}}</p>
	<br/>
	<n-input placeholder="题目组名" v-model:value="topic_name"></n-input>
	<br/>
	<br/>
	<n-select   placeholder="选择 题目类型"
	            v-model:value="topicType_select_value"
	            :options="topicType_select_options" ></n-select>
	<br/>
	<n-select   placeholder="选择 字符串分析器"
					v-model:value="str_select_value"
					:options="str_select_options"></n-select>
	<br/>
	<n-select   placeholder="选择 对象生成器"
	            v-model:value="object_select_value"
	            :options="object_select_options"></n-select>
	<br/>
	
	<n-button :disabled="!if_try_analyze" @click="TryAnalizy" >尝试分析</n-button>
	<br/>	<br/>
	<div>
		以分析题目组数量: {{topic_s.length}}
		<br/><br/>
		<div v-for="(v,k) in topic_s">
			<div>
				name:{{v.topic_name}}<br/>
				type:{{v.topic_type}}<br/>
				length:{{v.topics.length}}<br/>
			</div>
			<br/>
		</div>
	</div>
	<n-button @click="SaveTopic">保存题目</n-button>
	
</div></template>

<script lang="ts" setup>
import {
	ref,
	reactive,
	computed,
	watchEffect,
	defineProps,
	withDefaults,
	defineEmits,
	defineExpose,
	useSlots,
	useAttrs,
	Ref,
    shallowReactive
} from 'vue';
import { useRouter, useRoute } from "vue-router";
import {题目类型} from "../Ts/题目类型";// @ts-ignore
import {Str分析器_单选题_1} from "../Ts/解析器/Str分析器.ts";// @ts-ignore
import {Str分析器, 对象生成器} from "../Ts/解析器.ts";// @ts-ignore
import {对象生成器_通用Topic} from "../Ts/解析器/对象生成器.ts";
import { useMessage } from 'naive-ui'
import {TopicGroup} from "../Ts/TopicGroup";
import {ITopic, ITopic_Enum} from "../Ts/Topic";
const message = useMessage();

const text = ref("");
const topic_name = ref("");
const topicType_select_value = ref(null);
const topicType_select_options = [
	{
		label:题目类型.None,
		value:题目类型.None
	},{
		label:题目类型.单选题,
		value:题目类型.单选题
	},
]

const str_select_value = ref(null)
const str_select_options = [
	{
		label:"单选题_1",
		value: "单选题_1",
		mete:Str分析器_单选题_1
	}
]
let str分析器:Str分析器 | null = null;
watchEffect(()=>{
	if(str_select_value.value==null)
		return;
	str_select_options
			.filter((v)=>v.value==str_select_value.value)
			.map((v)=>str分析器=v.mete)
});



const object_select_value  = ref(null)
const object_select_options = [
	{
		label:"通用Topic",
		value: "通用Topic",
		mete:对象生成器_通用Topic
	}
]
let object生成器 : 对象生成器<any,any> | null = null;
watchEffect(()=>{
	if(object_select_value.value==null)
		return;
	object_select_options
			.filter((v)=>v.value==object_select_value.value)
			.map((v)=>object生成器=v.mete)
});

/// 是否可以尝试分析
const if_try_analyze = computed(()=>{
	if(text.value.length == 0
			|| topic_name.value.length == 0
			|| topicType_select_value.value == null
			|| str_select_value.value == null
			|| object_select_value.value == null)
		return false;
	return true;
})

function TryAnalizy(){
	if(str分析器==null || object生成器==null)return;//虽然不可能是null,但是这样写IDE给补全 ^_^
	let a = str分析器.try_analizys(text.value);
	if(a==null){
		message.error("[字符串分析器]分析失败!");
		return;
	}
	let b = object生成器.try_ass(a);
	if(b==null){
		message.error("[对象生成器]分析失败!");
		return;
	}
	for(let v in b){
		b[v].topics_name.value = topic_name.value;
		b[v].index.value = v;//这个不重要,后续会被修改
		b[v].type.value = topicType_select_value.value;
	}
	let topic_enum = object生成器.itopic_enum;
	topic_s[topic_s.length] = {
		topic_name:topic_name.value,
		topic_type:topicType_select_value.value,
		topic_enum:topic_enum,
		topics:b
	}
}

const topic_s :any[] = shallowReactive([]);//any糊弄一下
function SaveTopic(){
	for(let v in topic_s){
		let e = topic_s[v].topic_enum;
		for(let t in topic_s[v].topics){
			TopicGroup.add_topic(topic_s[v].topics[t],e);
		}
	}
}

</script>


<style scoped>

</style>
<!--
	流程:
		`start -> 输入字符串 -> 输入题目组名 -> 选择默认题目类型(不在这里提供修改类型的东东,可以在做题时修改)
		 -> 选择 Str分析器 -> 选择 对象生成器 -> 尝试生成
			N -> 给出失败提示
			Y -> 加入题目组
				继续录入题目 -> `start
				确定加入的题目 -> 加入本地存储的题目组,如果重名则追加
			
			
-->